import { request } from 'umi';
import ProForm, { ModalForm } from '@ant-design/pro-form';
import { message } from 'antd';
import { api } from '@/global';

export default (props: any) => {
  return (
    <div style={{ display: props.currentId === 7 ? 'none' : '' }}>
      <ModalForm<{
        name: string;
        company: string;
      }>
        title="删除角色"
        trigger={<a>删除</a>}
        autoFocusFirstInput
        modalProps={{
          onCancel: () => console.log('run'),
        }}
        onFinish={async () => {
          const result = await request(api.deleteRole, {
            method: 'POST',
            data: {
              id: props?.currentId,
            },
            skipErrorHandler: true,
          }).catch((e) => {
            if (e.response.status === 500) {
              message.error('该角色下面有用户存在');
            }
            return true;
          });

          if (result.success) {
            message.info('删除成功');
            props.reloadPage();
            return true;
          } else {
            message.error('删除失败');
            return true;
          }
        }}
      >
        是否删除该 &nbsp;&nbsp;
        <span style={{ fontSize: '30px', color: '#3498db', fontWeight: '900' }}>
          {props.curentName}
        </span>{' '}
        &nbsp;&nbsp;角色
      </ModalForm>
    </div>
  );
};
